import RequestURL from "@/Network/RequestURL/RequestURL.js"

export const myRequest = (options)=>{
	return new Promise(function (resolve, reject){
		var token = uni.getStorageSync('token');
		let header = {};
		if(token){
			header = {'token':token};
		}
		uni.request ({
		url: RequestURL.baseUrl+options.url, 
		method: options.method || 'GET' ,
		data: options.data || {},
		header:header,
		success: (res)=>{
			resolve(res.data)
			if(res.data.code == 401){
				console.log("token过期")
				uni.showToast({
					title:'登录过期'
				})
				// this.$tim.logout()
				uni.removeStorageSync('token')
				uni.removeStorageSync('nickname')
				uni.removeStorageSync('mobile')
				// uni.reLaunch({
				// 	url:'/pages/login/login'
				// })
			}
		}, 
		fail: (err)=>{
			// uni.showToast({
			// 	title:'请求接口失败'
			// })
			reject (err)
			}
		})
	});
}